package com.example.springcloud.consumer.student.controller;

import com.example.springcloud.common.entity.ResponseResult;
import com.example.springcloud.consumer.student.cloudclient.StudentFeignClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/consumer/time")
@Slf4j
public class TimeoutController {
    private final StudentFeignClient studentFeignClient;

    public TimeoutController(@Qualifier("com.example.springcloud.consumer.student.cloudclient.StudentFeignClient") StudentFeignClient studentFeignClient) {
        this.studentFeignClient = studentFeignClient;
    }

    // @HystrixCommand(fallbackMethod = "timeoutFallback")
    @GetMapping("ok")
    public ResponseResult<?> getOk() {
        log.info("consumer time-ok");
        return studentFeignClient.getOk();
    }

    // @HystrixCommand(fallbackMethod = "timeoutFallback", commandProperties = {
    //         @HystrixProperty(name = "circuitBreaker.enabled", value = "true"),
    //         @HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "10"),
    //         @HystrixProperty(name = "circuitBreaker.sleepWindowInMilliseconds", value = "10000"),
    //         @HystrixProperty(name = "circuitBreaker.errorThresholdPercentage", value = "60"),
    // }
    // )
    @GetMapping("out")
    public ResponseResult<?> getOut() {
        log.info("consumer time-out");
        return studentFeignClient.getOut();
    }

    @SuppressWarnings("unused")
    public ResponseResult<?> timeoutFallback() {
        log.info("timeout-fallback");
        return new ResponseResult<>(500, "timeout", "fallback");
    }
}
